//
//  LocalDisNumSetViewController.m
//  5gtonghua
//
//  Created by longziyuan on 14-6-24.
//
//

#import "LocalDisNumSetViewController.h"
#import "iToast.h"
@interface LocalDisNumSetViewController ()

@end

@implementation LocalDisNumSetViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"本地区号设置";
    
    localDisTable=[[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped]autorelease];
    localDisTable.delegate=self;
    localDisTable.dataSource=self;
    [self.view addSubview:localDisTable];
    
    
    
    UIBarButtonItem* confirmButton=[[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(confirmAction)];
    self.navigationItem.rightBarButtonItem=confirmButton;
    [confirmButton release];
    
    
    
    
    
}

-(void)confirmAction
{
    if ([DistricNumField.text length]>5||[DistricNumField.text length]<3) {
        
        iToast* toast=[iToast makeText:@"你输入的本地区号不正确!"];
        [toast show];

    }else
    {
        NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
        [defaults setObject:DistricNumField.text forKey:@"bendiquhao"];
        [defaults synchronize];
        
        
        iToast* toast=[iToast makeText:@"设置成功!"];
        [toast show];
        
    }
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* str=@"cell";
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:str];
    if (cell==nil) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str]autorelease];
        cell.textLabel.text=@"本地区号:";
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        DistricNumField=[[[UITextField alloc]initWithFrame:CGRectMake(95, 10, 200, 25)]autorelease];
        DistricNumField.borderStyle=UITextBorderStyleBezel;
        DistricNumField.keyboardType=UIKeyboardTypeNumberPad;
        [cell.contentView addSubview:DistricNumField];
        
        
    }
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"bendiquhao"])
    {
        NSString* quhao=[[NSUserDefaults standardUserDefaults] objectForKey:@"bendiquhao"];
        DistricNumField.text=quhao;
    }
    return cell;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
